home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Directory source / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-28  |  3.2 KB  |  179 lines  |  [TEXT/KAHL]

  1. /*    Print.c
  2.  *
  3.  *    Handle printing this window.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "struct.h"
  8.  
  9.  
  10. THPrint hPrint = NULL;
  11. WindowPtr statusWindow;
  12. char printMsg[] = "Now printing.  To halt, hit control-'.'; this seems to do the trick...";
  13.  
  14.  
  15. /*    OpenWarning
  16.  *
  17.  *    Open a warning window in the center of the screen
  18.  */
  19.  
  20. OpenWarning()
  21. {
  22.     GrafPtr foo;
  23.     int x,y;
  24.     Rect r;
  25.  
  26.     GetWMgrPort(&foo);
  27.     r = foo->portRect;
  28.     x = (r.right - r.left - 200) / 2;
  29.     y = (r.bottom - r.top - 100) / 2;
  30.     r.top = y;
  31.     r.bottom = r.top + 100;
  32.     r.left = x;
  33.     r.right = r.left + 200;
  34.     statusWindow = NewWindow(NULL,&r,"",1,1,(char *)-1,0,0L);
  35.     SetPort(statusWindow);
  36.     TextFont(0);
  37.     TextSize(12);
  38.     r.bottom -= r.top;
  39.     r.top = 0;
  40.     r.right -= r.left;
  41.     r.left = 0;
  42.     InsetRect(&r,8,8);
  43.     TextBox(printMsg,(long)strlen(printMsg),&r,0);
  44. }
  45.  
  46.  
  47. /*    CloseWarning
  48.  *
  49.  *    Close print warning
  50.  */
  51.  
  52. CloseWarning()
  53. {
  54.     DisposeWindow(statusWindow);
  55. }
  56.  
  57.  
  58.  
  59. /*    PrintStl
  60.  *
  61.  *    Print style dialog
  62.  */
  63.  
  64. PrintStl()
  65. {
  66.     PrOpen();
  67.     if (hPrint == NULL) {
  68.         hPrint = (THPrint)NewHandle(sizeof(TPrint));
  69.         if (hPrint == NULL) return;
  70.         PrintDefault(hPrint);
  71.     }
  72.     
  73.     PrStlDialog(hPrint);
  74.     PrClose();
  75. }
  76.  
  77.  
  78.  
  79. /*    PrintJob
  80.  *
  81.  *    Print job dialog
  82.  */
  83.  
  84. PrintJob()
  85. {
  86.     struct WindDraw *w;
  87.     long len;
  88.     long x;
  89.     struct DirectData *ptr;
  90.     long pagenum;
  91.     TPPrPort pPrPort;
  92.     TPrStatus myPrStatus;
  93.     short ind;
  94.     short xx;
  95.     Rect r;
  96.     short pageNum;
  97.     char buffer[64];
  98.  
  99.     if (NULL == (w = (struct WindDraw *)FrontWindow())) return;
  100.     if (w->w.windowKind != WK_PLAN) return;
  101.     
  102.     PrOpen();
  103.     if (hPrint == NULL) {
  104.         hPrint = (THPrint)NewHandle(sizeof(TPrint));
  105.         if (hPrint == NULL) return;
  106.         PrintDefault(hPrint);
  107.     }
  108.     
  109.     if (PrJobDialog(hPrint)) {
  110.         OpenWarning();
  111.         
  112.         HLock(w->data);
  113.         ptr = *(w->data);
  114.         len = GetHandleSize(w->data) / sizeof(struct DirectData);
  115.         pPrPort = PrOpenDoc(hPrint,NULL,NULL);
  116.         SetPort(pPrPort);
  117.         r = (**hPrint).prInfo.rPage;                /* Page rectangle */
  118.         r.bottom -= 15;
  119.         x = 0;
  120.         pageNum = 1;
  121.         while (x < len) {
  122.             if (PrError() == noErr) {
  123.                 PrOpenPage(pPrPort,NULL);
  124.                 
  125.                 TextFont(4);
  126.                 TextSize(9);
  127.                 sprintf(buffer,"Page %d",pageNum);
  128.                 CtoPstr(buffer);
  129.                 MoveTo(r.right - 20 - StringWidth(buffer),25);
  130.                 DrawString(buffer);
  131.                 
  132.                 sprintf(buffer,"Directory listing of %s",w->vName);
  133.                 CtoPstr(buffer);
  134.                 MoveTo(r.left + 20, 25);
  135.                 DrawString(buffer);
  136.                 
  137.                 MoveTo(r.left + 10, 28);
  138.                 LineTo(r.right - 10, 28);
  139.                 MoveTo(r.left + 10, 30);
  140.                 LineTo(r.right - 10, 30);
  141.  
  142.                 xx = 40 + r.top;
  143.                 if (PrError() == noErr) {
  144.                     while ((xx < r.bottom) && (x < len)) {
  145.                         for (ind = 0; ind < ptr[x].indent; ind++) {
  146.                             MoveTo(ind*12+25,xx-10);
  147.                             Line(0,12);
  148.                         }
  149.     
  150.                         MoveTo(ptr[x].indent*12+20,xx);
  151.                         DrawString(ptr[x].data);
  152.     
  153.                         if (ptr[x].auxdata[0] != '\0') {
  154.                             MoveTo(ptr[x].indent*12+25+StringWidth(ptr[x].data),xx);
  155.                             LineTo(305,xx);
  156.                             MoveTo(370 - StringWidth(ptr[x].auxdata),xx);
  157.                             DrawString(ptr[x].auxdata);
  158.                             
  159.                             MoveTo(390,xx);
  160.                             DrawString(ptr[x].auxdata2);
  161.                         }
  162.                         x++;
  163.                         xx += 12;
  164.                     }
  165.                 }
  166.                 PrClosePage(pPrPort);
  167.                 pageNum++;
  168.             } else break;
  169.         }
  170.         PrCloseDoc(pPrPort);
  171.         if (((**hPrint).prJob.bJDocLoop == bSpoolLoop) && (PrError() == noErr)) {
  172.             PrPicFile(hPrint,NULL,NULL,NULL,&myPrStatus);
  173.         }
  174.  
  175.         CloseWarning();
  176.     }
  177.     PrClose();
  178. }
  179.